package org.x4444;

import java.io.Serializable;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.x4444.entity.OrderP;


@Stateful
public class OrderZBean implements OrderZ, Serializable {
	
	private static final long serialVersionUID = -7152542759303805621L;
	
	@PersistenceContext
	EntityManager em;

	@Override
	public String getClient() {
		String res = Boolean.toString(em==null);
		if (em != null) {
			OrderP order = em.find(OrderP.class, new Integer(1));
			res = order.getClient();
		} else {
			res = "em is null";
		}
		return "Client " + res;
	}

	@Override
	public int getCount() {
		return 0;
	}

	@Override
	public String getProduct() {
		return "Product";
	}
	
	//OrderP order;
	
	@Override
	public OrderP getOrder(Integer id) {
		if (em != null) {
			OrderP order = em.find(OrderP.class, new Integer(1));
			return order;
		}
		return null;
	}
	
	@Override
	public void saveOrder(OrderP orderP) {
		if (em != null) {
			em.merge(orderP);
		}
	}
}
